import query from '@dfeidao/atom-nodejs/db/query';
// import { systemid } from 'src/atom/config';

interface Message {
	productid: string;
	formgroup_no: string;
}

interface D {
	role_no: string;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';
	const { exec, prepare } = query(action_id, session_id, systemid);

	prepare('pub_role_allot', ['_id', 'role_no', 'pk_val', 'productid'], { productid: msg.productid, pk_val: msg.formgroup_no }, 199, 1, [], []);
	const [data] = await exec<D>();
	const rey = new Array();
	data.forEach((item) => {
		rey.push(item.role_no);
	});
	prepare('pub_user_connect', ['_id', 'usercode', 'role_no', 'pk_val', 'search_field_val', 'create_time', 'productid'], { role_no: { $in: rey } }, 199, 1, [], []);

	const ret = await exec();
	return ret;
}
